#ifndef GRAPHICSITEMGROUP_H
#define GRAPHICSITEMGROUP_H

#include <QtCore/QObject>
#include "gelement.h"
#include <QtGui/QMenu>
#include <QtCore/QVector>
class DActiveElement;
class Link;

class GActiveElement : public GElement
{
public:
	GActiveElement(DActiveElement * pDActiveElement, QGraphicsItem * parent = 0);
	~GActiveElement();

	//DActiveElement* description() const { qobject_cast<DActiveElement*>(keyDElement); }

	void removeLink(Link * arrow);
	void addLink(Link * arrow, const QString & portName);
	QList<Link*> allLinks() const;

	// Enable the use of qgraphicsitem_cast with this item.
	enum { Type = UserType + 2 };
	int type() const { return Type; }

	//Is the Graphics a hited port in this object.
	//If it is, hold its index in mHitPortIndex.
	bool isHitPort(QGraphicsSvgItem* hitedGraphics);
	QGraphicsSvgItem* portFromName(const QString portName) const;
	QString portName(QGraphicsSvgItem* port) const;
	QString portDirection(QGraphicsSvgItem* hitedGraphics) const;

	QString getSubFilePath() const;

	bool portNameVisible() { return mShowName; }
	void flipPortNameVisible();

protected:
	/********************************************************
	**	When item is moved, this member function is called
	*********************************************************/
	QVariant itemChange(GraphicsItemChange change, const QVariant &value);
	
private:
	// parse the DElement *de to get the port graphics
	void parsePort(void);

private:
	//bijection with DActiveElement's mPorts
	QVector<QGraphicsSvgItem*> mPorts;
	QVector<QGraphicsTextItem*> mPortsName;
	int mHitPortIndex;
	bool mShowName;

	QMap<Link*, QGraphicsSvgItem*> mLinks; //no possible an identify point to itself

	//share QSvgRenderer
	static QSvgRenderer port;
	static QSvgRenderer multiPort;
};

#endif // GRAPHICSITEMGROUP_H
